// 邮箱验证
// 设置跳转标示
var k1 =false
var k2 =false
var k3 =false
var k4 =false

$('#email').focusout(function(){
	if($('#email').val() == ''){
		$('#cunzai1').attr({'src':'/homes/js/images/error.png'})
		$('#one').text('邮箱不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		var ret = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		if(!ret.test($('#email').val())){
			$('#cunzai1').attr({'src':'/homes/js/images/error.png'})
			$('#one').text('邮箱格式不正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$.get('/ajax/index','email='+$('#email').val(), function(a){
				// alert(a)
			if(a == 1){
					$('#cunzai1').attr({'src':'/homes/js/images/error.png'})
					$('#one').text('邮箱已存在').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
			}else if(a == 2){
					 k1 = true
					$('#cunzai1').attr({'src':'/homes/js/images/right.png'})
					$('#one').text('恭喜邮箱可以使用').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
				}
			})
		}
	}

	
}).focusin(function(){
	$('#cunzai1').attr({'src':''})
	$('#one').text('')
})

$('#password').focusin(function(){
	$('#cunzai2').attr({'src':''})
	$('#two').text('')
}).focusout(function(){
	// alert(11)
	if($('#password').val() == ''){
		$('#cunzai2').attr({'src':'/homes/js/images/error.png'})
		$('#two').text('密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		var pattern = /^[a-zA-Z]\w{7,15}$/
		// alert($('#password').val())
		var res = pattern.test($('#password').val())
		// alert(res)

		if(!res){
			$('#cunzai2').attr({'src':'/homes/js/images/error.png'})
			$('#two').text('密码请填写以字母开头的6-18位').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$('#cunzai2').attr({'src':'/homes/js/images/right.png'})
			$('#two').text('密码可以用').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
			 k2 = 1
		}
	}
	
	
})
$('#passwordRepeat').focusin(function(){
	$('#cunzai3').attr({'src':''})
	$('#three').text('')
}).focusout(function(){
	if($('#passwordRepeat').val() == ''){
		$('#cunzai3').attr({'src':'/homes/js/images/error.png'})
		$('#three').text('确认密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		if($('#passwordRepeat').val() != $('#password').val()){
			$('#cunzai3').attr({'src':'/homes/js/images/error.png'})
			$('#three').text('密码与确认密码不一致').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$('#cunzai3').attr({'src':'/homes/js/images/right.png'})
			$('#three').text('确认密码与密码一致').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
			 k3 =1
		}
	}
	
	
})
$('#code').focusout(function(){
	if($('#code').val() == ''){
			$('#cunzai4').attr({'src':'/homes/js/images/error.png'})
			$('#four').text('验证码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		// alert(1)
		$.get('/ajax/code',function(b){
			if($('#code').val() != b){
				$('#cunzai4').attr({'src':'/homes/js/images/error.png'})
				$('#four').text('验证码不正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
			}else{
				$('#cunzai4').attr({'src':'/homes/js/images/right.png'})
				$('#four').text('验证码正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
				 k4 = 1
			}
		})

	}

}).focusin(function(){
		$('#cunzai4').attr({'src':''})
		$('#four').text('')
	})

function fun(){
	// alert($('input:checked').val())
	if(!k1){
		$('#cunzai1').attr({'src':'/homes/js/images/error.png'})
		$('#one').text('邮箱不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!k2){
		$('#cunzai2').attr({'src':'/homes/js/images/error.png'})
		$('#two').text('密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!k3){
		$('#cunzai3').attr({'src':'/homes/js/images/error.png'})
		$('#three').text('确认密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!k4){
		$('#cunzai4').attr({'src':'/homes/js/images/error.png'})
		$('#four').text('验证码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!$('input:checked').val()){
		$('#cunzai5').attr({'src':'/homes/js/images/error.png'})
		$('#five').text('请点击表示您同意商城《服务协议》').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else{
		return true;
	}

	
	
}


// 手机发送验证码
var time = null;
function get_mobile_code(){
	$.ajaxSetup({
		        headers: {
		            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		        }
		});

    $.post('/home/register/phone', {mobile:$('#phone').val()}, function(msg) {
        alert(jQuery.trim(unescape(msg)));
			if($('#phone').val() == ''){
			$('#cunzai6').attr({'src':'/homes/js/images/error.png'})
			$('#six').text('手机号不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}

		if(msg=='提交成功'){
			// RemainTime();
			var i = 60;
			
			if(time == null){
				time = setInterval(function(){	
					i--
					if(i < 1){
						$('#dyMobileButton').text('重新获取')
						// session(['phone_code' => '']);
					}else{
						$('#dyMobileButton').text(i+'秒')
					}
					// console.log(i);
					if(i < 0){
						clearInterval(time);
						time = null;
					}
					
				},1000);
			}

		}
    });

};
var iTime = 59;
var Account;


// 手机号验证
// 设置跳转标示
var v1 =false
var v2 =false
var v3 =false
var v4 =false

$('#phone').focusout(function(){
	if($('#phone').val() == ''){
		$('#cunzai6').attr({'src':'/homes/js/images/error.png'})
		$('#six').text('手机号不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		var ret = /^1[34578]\d{9}$/;
		if(!ret.test($('#phone').val())){
			$('#cunzai6').attr({'src':'/homes/js/images/error.png'})
			$('#six').text('手机号格式不正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$.get('/ajax/index2','tel='+$('phone').val(), function(a){
				// alert(a)
			if(a == 1){
					$('#cunzai6').attr({'src':'/homes/js/images/error.png'})
					$('#six').text('手机号已存在').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
			}else if(a == 2){
					 v1 = true
					$('#cunzai6').attr({'src':'/homes/js/images/right.png'})
					$('#six').text('恭喜手机号可以使用').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
				}
			})
		}
	}

	
}).focusin(function(){
	$('#cunzai6').attr({'src':''})
	$('#six').text('')
})

$('#telpassword').focusin(function(){
	$('#cunzai8').attr({'src':''})
	$('#ba').text('')
}).focusout(function(){
	// alert(11)
	if($('#telpassword').val() == ''){
		$('#cunzai8').attr({'src':'/homes/js/images/error.png'})
		$('#ba').text('密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		var pattern = /^[a-zA-Z]\w{7,15}$/
		// alert($('#password').val())
		var res = pattern.test($('#telpassword').val())
		// alert(res)

		if(!res){
			$('#cunzai8').attr({'src':'/homes/js/images/error.png'})
			$('#ba').text('密码请填写以字母开头的6-18位').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$('#cunzai8').attr({'src':'/homes/js/images/right.png'})
			$('#ba').text('密码可以用').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
			 v2 = 1
		}
	}
	
	
})
$('#telpasswordRepeat').focusin(function(){
	$('#cunzai9').attr({'src':''})
	$('#jiu').text('')
}).focusout(function(){
	if($('#telpasswordRepeat').val() == ''){
		$('#cunzai9').attr({'src':'/homes/js/images/error.png'})
		$('#jiu').text('确认密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		if($('#telpasswordRepeat').val() != $('#telpassword').val()){
			$('#cunzai9').attr({'src':'/homes/js/images/error.png'})
			$('#jiu').text('密码与确认密码不一致').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		}else{
			$('#cunzai9').attr({'src':'/homes/js/images/right.png'})
			$('#jiu').text('确认密码与密码一致').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
			 v3 =1
		}
	}
	
	
})
$('#telcode').focusout(function(){
	if($('#telcode').val() == ''){
			$('#cunzai7').attr({'src':'/homes/js/images/error.png'})
			$('#qi').text('验证码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
	}else{
		// alert(1)
		$.get('/ajax/code2',function(b){
			if($('#telcode').val() != b){
				$('#cunzai7').attr({'src':'/homes/js/images/error.png'})
				$('#qi').text('验证码不正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
			}else{
				$('#cunzai7').attr({'src':'/homes/js/images/right.png'})
				$('#qi').text('验证码正确').attr({'style':'font-size:12px;position:relative;top:-3px;color:green;'})
				 v4 = 1
			}
		})

	}

}).focusin(function(){
		$('#cunzai7').attr({'src':''})
		$('#qi').text('')
	})

function fun2(){
	// alert($('input:checked').val())
	if(!v1){
		$('#cunzai6').attr({'src':'/homes/js/images/error.png'})
		$('#six').text('手机号不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!v4){
		$('#cunzai7').attr({'src':'/homes/js/images/error.png'})
		$('#qi').text('验证码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false}
	else if(!v2){
		$('#cunzai8').attr({'src':'/homes/js/images/error.png'})
		$('#ba').text('密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!v3){
		$('#cunzai9').attr({'src':'/homes/js/images/error.png'})
		$('#jiu').text('确认密码不能为空').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else if(!$('input:checked').val()){
		$('#cunzai10').attr({'src':'/homes/js/images/error.png'})
		$('#shi').text('请点击表示您同意商城《服务协议》').attr({'style':'font-size:12px;position:relative;top:-3px;color:red;'})
		return false
	}else{
		return true;
	}

	
	
}